<?php
/**
 * Created by PhpStorm.
 * User: yy
 * Date: 2019/5/15
 * Time: 15:14
 */

namespace app\common\validate\environmentAnalysis;

use think\Validate;

class EnvironmentAnalysisPollutantValidate extends Validate
{
    protected $rule = [
        'start_time'                => 'require',
        'end_time'                  => 'require',
        'contribute_pollutant_name' => 'require|check_contribute_pollutant_name:contribute_pollutant_name错误',
        'company_pollutant_name'    => 'require|check_company_pollutant_name:company_pollutant_name错误',
        'primary_pollutant_name'    => 'require|check_primary_pollutant_name:primary_pollutant_name错误',
        'industry_id'               => 'require',
        'region_id'                 => 'require',
        'station_id'                => 'require',
        'company_id'                => 'require',
        'select_type'               => 'require|check_select_type:check_select_type错误',
    ];
    protected $message = [
        'start_time.require'                => '请选择开始时间',
        'end_time.require'                  => '请选择结束时间',
        'contribute_pollutant_name.require' => '请选择污染物类型',
        'company_pollutant_name.require'    => '请选择脱硫脱硝',
        'industry_id.require'               => '请选择行业类型',
        'region_id.require'                 => '缺少region_id',
        'station_id.require'                => '缺少station_id',
        'company_id.require'                => '缺少company_id',
        'aqi_level.require'                 => '请选择空气质量等级',
        'select_type.require'               => '请选择按行业或者按企业',
    ];
    protected $scene = [
        'table'                       => ['start_time', 'end_time', 'region_id'],
        'emissionRank'                => ['start_time', 'end_time', 'region_id', 'company_pollutant_name', 'industry_id'],
        'primaryPollutantTrend'       => ['start_time', 'end_time', 'region_id', 'station_id', 'primary_pollutant_name'],
        'industryEmissionTrend'       => ['start_time', 'end_time', 'industry_id', 'company_pollutant_name'],
        'companyEmissionTrend'        => ['start_time', 'end_time', 'company_pollutant_name', 'industry_id', 'company_id'],
        'industryCompanyEmissionRate' => ['start_time', 'end_time', 'region_id', 'company_pollutant_name'],
        'contributionRank'            => ['start_time', 'end_time', 'region_id', 'industry_id', 'contribute_pollutant_name'],
        'industryContributeTrend'     => ['start_time', 'end_time', 'region_id', 'station_id', 'industry_id', 'contribute_pollutant_name'],
        'companyContributeTrend'      => ['start_time', 'end_time', 'region_id', 'station_id', 'industry_id', 'company_id', 'contribute_pollutant_name'],

    ];

    /**
     * 溯源物类型判断
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     * @author yy by 2019/5/10
     */
    protected function check_contribute_pollutant_name($value, $rule, $name, $description, $data = [])
    {
        if (!in_array(strtolower($value), ['pm2.5', 'so2', 'no2'])) {
            return $rule;
        } else {
            return true;
        }
    }

    /**
     * 脱硫脱硝参数判断
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     * @author yy by 2019/5/10
     */
    protected function check_company_pollutant_name($value, $rule, $name, $description, $data = [])
    {
        if (!in_array(strtolower($value), ['so2', 'nox', 'smoke'])) {
            return $rule;
        } else {
            return true;
        }
    }

    /**
     * 按行业按企业判断
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     * @author yy by 2019/5/10
     */
    protected function check_select_type($value, $rule, $name, $description, $data = [])
    {
        if (!in_array(strtolower($value), ['industry', 'company'])) {
            return $rule;
        } else {
            return true;
        }
    }

    /**
     * 检测首要污染物
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     * @author yy by 2019/5/16
     */
    protected function check_primary_pollutant_name($value, $rule, $name, $description, $data = [])
    {
        if (!in_array(strtolower($value), ['pm10', 'pm2.5', 'co', 'o3', 'no2', 'so2'])) {
            return $rule;
        } else {
            return true;
        }
    }
}